<template>
  <div>
    <a-card :bordered="false" style="margin-bottom: 10px">
      <!-- 条件搜索 -->
      <div class="table-page-search-wrapper">
        <a-form :labelCol="labelCol" :wrapperCol="wrapperCol" ref="queryForm">
          <a-row :gutter="32">
            <a-col :span="4">
              <a-form-item label="撞库电话">
                <a-input
                  v-model="queryParam.originPhone"
                  placeholder="请输入撞库电话"
                  allow-clear
                  @keyup.enter.native="handleQuery"
                />
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="电话位数">
                <a-input-number
                  v-model="queryParam.originLength"
                  :min="0"
                  style="width: 100%"
                />
              </a-form-item>
            </a-col>

            <a-col :span="4">
              <a-form-item label="撞库来源" prop="type">
                <a-select
                  placeholder="选择撞库来源"
                  v-model="queryParam.originLaiyuan"
                  style="width: 100%"
                  allow-clear
                >
                  <a-select-option
                    v-for="(d, index) in laiyuanOptions"
                    :key="index"
                    :value="d.dictValue"
                    >{{ d.dictLabel }}</a-select-option
                  >
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="客户来源" prop="type">
                <a-select
                  placeholder="选择客户来源"
                  v-model="queryParam.laiyuan"
                  style="width: 100%"
                  allow-clear
                >
                  <a-select-option
                    v-for="(d, index) in laiyuanOptions"
                    :key="index"
                    :value="d.dictValue"
                    >{{ d.dictLabel }}</a-select-option
                  >
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="城市区域" prop="type">
                <a-select
                  placeholder="所在城市"
                  v-model="queryParam.cityNames"
                  style="width: 100%"
                  mode="multiple"
                  allow-clear
                >
                  <a-select-option
                    v-for="(d, index) in cityOptions"
                    :key="index"
                    :value="d.name.replace('市', '')"
                    >{{ d.name }}</a-select-option
                  >
                </a-select>
              </a-form-item>
            </a-col>

            <a-col>
              <span
                class="table-page-search-submitButtons"
                style="float: right"
              >
                <a-button type="primary" @click="handleQuery"
                  ><a-icon type="search" />查询</a-button
                >
                <a-button style="margin-left: 8px" @click="resetQuery"
                  ><a-icon type="redo" />重置</a-button
                >
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false" class="table-card">
      <!-- 增加 -->
      <biz-zhuangku-log-add-form
        v-if="showAddModal"
        ref="bizZhuangkuLogAddForm"
        @ok="getList"
        @close="showAddModal = false"
      />
      <!-- 编辑 -->
      <biz-zhuangku-log-edit-form
        v-if="showEditModal"
        ref="bizZhuangkuLogEditForm"
        @ok="getList"
        @close="showEditModal = false"
        :laiyuanOptions="laiyuanOptions"
      />
      <!--跟进记录-->
      <biz-customer-info-shadow-form
        v-if="showShadowModal"
        ref="bizCustomerInfoShadowForm"
        :typeOptions="typeOptions"
        :levelOptions="levelOptions"
        :progressOptions="progressOptions"
        :statusOptions="statusOptions"
        :ideasTypeOptions="ideasTypeOptions"
        :zxInfoOptions="zxInfoOptions"
        :zhichanInfoOptions="zhichanInfoOptions"
        :genjinQuckitInputOptions="genjinQuckitInputOptions"
        :sexOptions="sexOptions"
        :fujianTypeOptions="fujianTypeOptions"
        :carTypeOptions="carTypeOptions"
        @ok="getList"
        @close="showShadowModal = false"
        :eidtshow="true"
      />
      <advance-table
        title="撞库日志"
        :pagination="{
          current: queryParam.pageNum,
          pageSize: queryParam.pageSize,
          total: total,
          showSizeChanger: true,
          showLessItems: true,
          showQuickJumper: true,
          showTotal: (total, range) =>
            `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
          onChange: changeSize,
          onShowSizeChange: onShowSizeChange,
        }"
        tableKey="base-bizZhuangkuLog-index-table"
        rowKey="id"
        size="middle"
        @refresh="getList"
        :columns="columns"
        :data-source="bizZhuangkuLogList"
        :loading="loading"
        :format-conditions="true"
        @change="handleTableChange"
        :row-selection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
      >
        <div class="table-operations" slot="button">
          <!-- <a-button
            type="primary"
            @click="handleAdd"
            v-hasPermi="['biz:bizZhuangkuLog:add']"
          >
            <a-icon type="plus" />新增
          </a-button> -->
          <a-button
            type=""
            @click="handleExport"
            v-hasPermi="['biz:bizZhuangkuLog:export']"
          >
            <a-icon type="download" />导出
          </a-button>
          <!-- <a-button
            type="danger"
            v-if="!multiple"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['biz:bizZhuangkuLog:remove']"
          >
            <a-icon type="delete" />删除
          </a-button> -->
        </div>

        <span slot="phone" slot-scope="{ text, record }">
          <a @click="handleShadow(record)" v-if="text" style="color: #f56c6c">
            {{ "*******" + text.substring(7, 11) }}
          </a>
          <!-- {{ text }} -->
        </span>
        <span slot="cusName" slot-scope="{ text, record }">
          <a @click="handleShadow(record)" v-if="text" style="color: #f56c6c">
            {{ text }}
          </a>
          <!-- {{ text }} -->
        </span>

        <span slot="operation" slot-scope="{ text, record }">
          <a
            @click="handleUpdate(record)"
            v-hasPermi="['biz:bizZhuangkuLog:edit']"
          >
            查看
          </a>
        </span>
        <span slot="rowindex" slot-scope="{ index }">
          {{ index + 1 }}
        </span>
      </advance-table>
    </a-card>
  </div>
</template>
<script>
import {
  listBizZhuangkuLog,
  delBizZhuangkuLog,
  exportBizZhuangkuLog,
} from "@/api/biz/bizZhuangkuLog";
import AdvanceTable from "@/components/pt/table/AdvanceTable";
import BizZhuangkuLogAddForm from "@/views/biz/zhuangkulog/modules/BizZhuangkuLogAddForm";
import BizZhuangkuLogEditForm from "@/views/biz/zhuangkulog/modules/BizZhuangkuLogEditForm";
import BizCustomerInfoShadowForm from "@/views/biz/customer/modules/BizCustomerInfoShadowForm";
import { findListByCode } from "@/api/biz/sysArea";
export default {
  name: "BizZhuangkuLog",
  components: {
    AdvanceTable,
    BizZhuangkuLogAddForm,
    BizZhuangkuLogEditForm,
    BizCustomerInfoShadowForm,
  },
  data() {
    return {
      showAddModal: false,
      showEditModal: false,
      showShadowModal: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 撞库日志表格数据
      bizZhuangkuLogList: [],
      // 客户来源字典
      laiyuanOptions: [],
      // 当前分页数据的ID数组
      cusListIds: [],

      // 状态字典
      statusOptions: [],
      // 申请类型字典
      typeOptions: [],
      // 业务进度
      progressOptions: [],
      levelOptions: [],
      ideasTypeOptions: [],
      // 征信信息
      zxInfoOptions: [],
      zhichanInfoOptions: [],
      genjinQuckitInputOptions: [],
      ownTypeOptions: [],
      fujianTypeOptions: [],
      businessStatusOptions: [],
      carStatusOptions: [],
      // 性别
      sexOptions: [],

      // 车辆类型
      carTypeOptions: [],
      // 城市列表
      cityOptions: [],

      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        originPhone: undefined,

        originLength: undefined,

        originLaiyuan: undefined,
      },
      columns: [
        {
          title: "序号",
          dataIndex: "rowindex",
          ellipsis: true,
          align: "center",
          width: "50px",
          scopedSlots: { customRender: "rowindex" },
        },
        {
          title: "撞库时间",
          dataIndex: "createTime",
          ellipsis: true,
          align: "center",
          width: "100px",
          sorter: true,
        },
        {
          title: "撞库电话",
          dataIndex: "originPhone",
          ellipsis: true,
          align: "center",
          width: "100px",
        },
        {
          title: "电话位数",
          dataIndex: "originLength",
          align: "right",
          width: "100px",
        },
        {
          title: "撞库来源",
          dataIndex: "originLaiyuan",
          ellipsis: true,
          align: "center",
          width: "100px",
        },

        {
          title: "客户姓名",
          dataIndex: "cusName",
          ellipsis: true,
          align: "center",
          width: "100px",
          scopedSlots: { customRender: "cusName" },
        },
        {
          title: "客户电话",
          dataIndex: "phone",
          ellipsis: true,
          align: "center",
          width: "100px",
          scopedSlots: { customRender: "phone" },
        },
        {
          title: "客户来源",
          dataIndex: "laiyuan",
          ellipsis: true,
          align: "center",
          width: "100px",
        },
        {
          title: "城市",
          dataIndex: "cityName",
          ellipsis: true,
          align: "center",
          width: "100px",
        },
        // {
        //   title: "操作",
        //   dataIndex: "operation",
        //   align: "center",
        //   width: "10%",
        //   scopedSlots: { customRender: "operation" },
        // },
      ],
    };
  },
  created() {
    this.getDicts("bus_type").then((response) => {
      this.laiyuanOptions = response.data;
    });
    this.getList();
    this.getDicts("customer_bus_status").then((response) => {
      this.businessStatusOptions = response.data;
    });
    this.getDicts("customer_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getDicts("customer_type").then((response) => {
      this.typeOptions = response.data;
    });
    this.getDicts("bus_progress").then((response) => {
      this.progressOptions = response.data;
    });
    this.getDicts("level_options").then((response) => {
      this.levelOptions = response.data;
    });
    this.getDicts("ideas_type_options").then((response) => {
      this.ideasTypeOptions = response.data;
    });
    this.getDicts("zx_info").then((response) => {
      this.zxInfoOptions = response.data;
    });
    this.getDicts("sys_user_sex").then((response) => {
      this.sexOptions = response.data;
    });
    this.getDicts("zhichan_info").then((response) => {
      this.zhichanInfoOptions = response.data;
    });
    this.getDicts("genjin_quckit_input").then((response) => {
      this.genjinQuckitInputOptions = response.data;
    });
    this.getDicts("own_type").then((response) => {
      this.ownTypeOptions = response.data;
    });
    this.getDicts("fujian_type").then((response) => {
      this.fujianTypeOptions = response.data;
    });
    this.getDicts("car_status_options").then((response) => {
      this.carStatusOptions = response.data;
    });
    this.getDicts("car_type").then((response) => {
      this.carTypeOptions = response.data;
    });
    this.handleFindCityList();
  },
  methods: {
    // 获取城市区域列表
    handleFindCityList() {
      findListByCode().then((res) => {
        this.cityOptions = res.data;
      });
    },
    // 客户跟踪信息
    handleShadow(record) {
      this.showShadowModal = true;
      record.id = record.customerId;
      this.$nextTick(() =>
        this.$refs.bizCustomerInfoShadowForm.handleShadow(
          record,
          this.cusListIds
        )
      );
    },
    /** 分页、删选、排序 */
    handleTableChange(pagination, filters, sorter) {
      if (
        sorter.order !== undefined &&
        sorter.order !== null &&
        sorter.order !== ""
      ) {
        this.queryParam.orderByColumn = "a." + sorter.field;
        if (sorter.order === "ascend") {
          this.queryParam.isAsc = "asc";
        } else if (sorter.order === "descend") {
          this.queryParam.isAsc = "desc";
        }
      } else {
        this.queryParam.orderByColumn = null;
        this.queryParam.isAsc = null;
      }
      this.getList();
    },
    /** 查询撞库日志列表 */
    getList() {
      this.loading = true;
      listBizZhuangkuLog(this.queryParam).then((response) => {
        this.bizZhuangkuLogList = response.data.list;
        this.cusListIds = response.data.list.map((item, index) => {
          return { id: item.customerId, index: index };
        });
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        originPhone: undefined,

        originLength: undefined,

        originLaiyuan: undefined,
      };
      this.handleQuery();
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1;
      this.queryParam.pageSize = size;
      this.getList();
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current;
      this.queryParam.pageSize = pageSize;
      // this.getList();
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.ids = this.selectedRows.map((item) => item.id);
      this.single = selectedRowKeys.length !== 1;
      this.multiple = !selectedRowKeys.length;
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced;
    },
    handleAdd() {
      this.showAddModal = true;
      this.$nextTick(() => this.$refs.bizZhuangkuLogAddForm.handleAdd());
    },
    handleUpdate(record, ids) {
      this.showEditModal = true;
      this.$nextTick(() =>
        this.$refs.bizZhuangkuLogEditForm.handleUpdate(record, ids)
      );
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var that = this;
      const bizZhuangkuLogIds = row.id || this.ids;
      this.$confirm({
        title: "确认删除所选中数据?",
        onOk() {
          return delBizZhuangkuLog(bizZhuangkuLogIds).then(() => {
            that.onSelectChange([], []);
            that.getList();
            that.$message.success("删除成功", 3);
          });
        },
        onCancel() {},
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      var that = this;
      this.$confirm({
        title: "是否确认导出?",
        content: "此操作将导出当前条件下所有数据而非选中数据",
        onOk() {
          return exportBizZhuangkuLog(that.queryParam).then((response) => {
            that.download(response.msg);
            that.$message.success("导出成功", 3);
          });
        },
        onCancel() {},
      });
    },
  },
};
</script>
